<?php

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateStudentProductsTableWhenTesting extends Migration
{
    protected $connection_billing = 'billing';
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        if (app()->environment() === 'testing') {
            Schema::connection($this->connection_billing)->create('student_products', function (Blueprint $table) {
                $table->timestamp('updated_at')->useCurrent();
                $table->timestamp('created_at');

                $table->increments('id');
                $table->integer('parent_id')->default(null)->nullable();
                $table->integer('refund_id')->default(null)->nullable();

                $table->integer('student_id');
                $table->integer('product_id');
                $table->integer('bill_id');

                $table->integer('consumption_id'); // 赔偿课时的消费ID

                // 课时统计
                $table->decimal('lesson_count');
                $table->decimal('lesson_count_frozen')->default(0);
                $table->decimal('lesson_count_used')->default(0);

                // 送课人员
                $table->integer('admin_id');

                // 单价
                $table->decimal('unit_price')->default(0);
                // 当前财务计算单价
                $table->decimal('current_accounting_price')->default(0);

                $table->tinyInteger('status');
                // 有效期
                $table->timestamp('validity_start_at');
                $table->timestamp('validity_finish_at');
                $table->softDeletes();
            });
        }
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        if (app()->environment() === 'testing') {
            Schema::connection($this->connection_billing)->drop('student_products');
        }
    }
}
